<style>
.item-up-content {background-color: #fff;border-radius: 10px;padding:0.5rem;margin:0.5rem 0}
.item-ng {}
.item-ng .deleteitem {position: absolute;color:#000;margin-top:-1rem;right:0.5rem}
</style>
<style>
.fui-number .minus:before, .fui-number .plus:before {
	border-left: 0 solid #d9d9d9;
}
.fui-number .minus:after, .fui-number .plus:after {
	border-right: 0 solid #d9d9d9;
}
.fui-number:before {
	border-top: 0 solid #d9d9d9;
}
.fui-number:after {border-top: 0 solid #d9d9d9;}
.fui-number .num {
	color:#666;
}
.fui-number .num {
	color:#666;
}
.fui-number.small {
	height: 1.2rem;
	line-height: 1.2rem;
}
.fui-number .minus, .fui-number .plus {
	z-index:0;
}
.fui-number.small .minus{
	color: {{main.syscolor || '#63BE72'}};
	padding-top:1px;
	border: 1px solid {{main.syscolor || '#63BE72'}};
	border-radius:50%;
}
 .fui-number.small .plus {
	color: #fff;
	padding-top:1px;
	background: {{main.syscolor || '#63BE72'}};
	border: 1px solid {{main.syscolor || '#63BE72'}};
	border-radius:50%;
}
	</style>
<div class='fui-page fui-page-current' ng-if="pagedata.op=='main'">
	<div class="fui-content">
	<div style="padding:0.5rem;">
	<div class="weui_cells weui_cells_form" style="margin-top:0">
				<div class="weui_cell weui_vcode">
					<div class="weui_cell_hd"><label class="weui_label">礼包名称<span class="must"></span></label></div>
					<div class="weui_cell_bd weui_cell_primary">
						<input class="weui_input" type="text" ng-model="pagedata.post.title" value="{{pagedata.post.title}}" placeholder="请输入DIY礼包名称">
					</div>
				</div>
	</div>
	<div class="weui_cells_title">礼包描述</div>
	<div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <textarea class="weui_textarea" ng-model="pagedata.post.desc" value="{{pagedata.post.desc}}" placeholder="请输入礼包描述" rows="3"></textarea>
                    <div class="weui_textarea_counter">建议68个字以内！</div>
                </div>
            </div>
    </div>
	<div class="weui_cells weui_cells_form" >
			<div class="weui_cell">
					<div class="weui_cell_hd"><label class="weui_label">礼包封面图<span class="must"></span></label></div>
					<div class="weui_cell_bd weui_cell_primary">
						<ul class="weui_uploader_files" ng-if="pagedata.post.image">
							  <li class="weui_uploader_file" style="background-image:url({{tomedia(pagedata.post.image)}})"></li>
						</ul>
						<div class="weui_uploader_input_wrp">
							 <input class="weui_uploader_input" ng-click="up_file(pagedata.post,'image','image')" accept="image/jpg,image/jpeg,image/png,image/gif" multiple="">
						</div>
					</div>
			</div>
	</div>
	<div class="item-up-content" style="padding:1rem;text-align:center;color:#999">
				<p>设置一项礼包内容</p>
				<p>(点击下面图标添加礼包内容)</p>
	</div>
	<div class="item-up-content">
				<div class="fui-icon-group noborder col-3" style="margin-top:0.5rem">
					<div class="fui-icon-col external" ng-click="pagedata.showselectgoods=true">
						<div class="icon icon-green radius" style="height:1.3rem;line-height:1.3rem;;"><i class="icon icon-gifts" style="font-size:1.2rem;color:#999;height:1.2rem;line-height:1.2rem;;"></i></div>
						<div class="text" style="color: #999;padding:0">商品</div>
					</div>
					<div class="fui-icon-col external" ng-click="pagedata.nowitem={'type':2};pagedata.showtype=2">
						<div class="icon icon-green radius" style="height:1.2rem;line-height:1.2rem;"><i class="icon icon-ai-hongbao" style="font-size:1.2rem;color:#999;height:1.2rem;line-height:1.2rem;"></i></div>
						<div class="text" style="color: #999;padding:0">余额红包</div>
					</div>
					<div class="fui-icon-col external" ng-click="pagedata.nowitem={'type':3};pagedata.showtype=3">
						<div class="icon icon-green radius" style="height:1.2rem;line-height:1.2rem;"><i class="icon icon-jifen1" style="font-size:1.2rem;color:#999;height:1.2rem;line-height:1.2rem;"></i></div>
						<div class="text" style="color: #999;padding:0">虚拟币</div>
					</div>
				</div>
	</div>
	<div class="weui_cells_title">礼包内容</div>
		<div class="item-up-content item-ng" ng-repeat="g in pagedata.post.jiangs">
				<div class="deleteitem" ng-click="pagedata.post.jiangs.splice($index,1)"><i class="icon icon-cuowu bold" style="color:#000"></i></div>
				<div class="fui-list-group goods-list-group" style="background:#fff;margin-top:0"> 
						<div ng-if="g.type<=0" class="fui-list">
							<div class="fui-list-media">
								<img ng-src="{{tomedia(g.goods.image)}}" class="round">
							</div>
							<div class="fui-list-inner">
								<div class="text goodstitle">{{g.goods.title}}</div>
								<div class="gray">{{g.goods.subtitle}}</div> 
							</div>
							<div class='fui-list-angle'>
							<span class='marketprice'>￥{{g.goods.price}}
							<div class="fui-number small" style="right:0">
								<div ng-if="g.total>0" class="minus" ng-click="pagedata.minus2($index)"><i class="icon icon-subtract" style="font-size:0.7rem"></i></div>
								{{g.total}}
								<div class="plus" ng-click="pagedata.plus2($index)"><i class="icon icon-tianjia" style="font-size:0.7rem"></i></div>
							</div>
							</div>
						</div>
						<div ng-if="g.type==2" class="fui-list">
							<div class="fui-list-media">
								<i class="icon icon-ai-hongbao syscolor" style="font-size:2.3rem"></i>
							</div>
							<div class="fui-list-inner">
								<div class="text goodstitle">[送现金红包]红包</div>
								<div class="gray">会员中心现金红包，可以提现</div> 
							</div>
							<div class='fui-list-angle'>
								<span class='marketprice'>￥{{g.num}}</span>
							</div>
						</div>
						<div ng-if="g.type==3" class="fui-list">
							<div class="fui-list-media">
								<i class="icon icon-jifen1 syscolor" style="font-size:2.3rem"></i>
							</div>
							<div class="fui-list-inner">
								<div class="text goodstitle">[送币]{{g.credit_title}}</div>
								<div class="gray">会员中心查看{{g.credit_title}}，可以消费抵扣</div> 
							</div>
							<div class='fui-list-angle'>
								<span class='marketprice'>{{g.num}}个</span>
							</div>
						</div>
				</div>
	    </div>	
	</div>
	<div class="weui_btn_area">
		<div class="fui-cellone">
			<div class="fui-cellone-label bold">礼包单价</div>
			<div class="fui-cellone-text" style="color:#333">
				￥{{pagedata.post.oneprice||'0.00'}}/个
			</div>
			<div class="fui-cellone-remark noremark">
				<div class="fui-cellone noborder" style="padding:0">
					<div class="fui-cellone-info"></div>
					<div class="fui-cell-mask noremark">
						 <div class="fui-number">
							<div class="minus" ng-click="pagedata.minus3()">-</div>
							<input class="num" type="number" name="" ng-model="pagedata.post.total"/>
							<div class="plus" ng-click="pagedata.plus3()">+</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<a class="weui_btn weui_btn_primary" style="padding:0.5rem;border-radius:2rem" href="javascript:" ng-click="pagedata.pay_submit(pagedata.post,'jy_shoplibao/diybao/post/','jy_shoplibao/orderlist/')">
			<div class="bold" style="line-height:1.5">￥{{pagedata.post.totalprice||'0.00'}}</div>
			<div style="line-height:1.5">确定购买礼包</div>
		</a>
	</div>
</div>
</div>
<div ng-if="pagedata.showtype" class="popup">
	<div class="popup-body">
		<div class="popup-bottom">
			<i class="closed icon icon-cuowu" ng-click="pagedata.showtype=false"></i>
			<div class="fui-content" style="padding-bottom:2.5rem">
				<div class="weui_cells weui_cells_form">
						<div class="weui_cell weui_vcode">
							<div class="weui_cell_hd"><label class="weui_label">礼品名称<span class="must"></span></label></div>
							<div class="weui_cell_bd weui_cell_primary">
								<input class="weui_input" type="text" ng-model="pagedata.nowitem.title" value="{{pagedata.nowitem.title}}" placeholder="请输入礼品名称">
							</div>
						</div>
						<div class="weui_cell weui_vcode">
							<div class="weui_cell_hd"><label class="weui_label">礼包描述<span></span></label></div>
							<div class="weui_cell_bd weui_cell_primary">
								<input class="weui_input" type="text" ng-model="pagedata.nowitem.desc" value="{{pagedata.nowitem.desc}}" placeholder="请输入礼包描述">
							</div>
						</div>
						<div ng-if="pagedata.showtype==3" class="weui_cell weui_vcode">
							<div class="weui_cell_hd"><label class="weui_label">虚拟币类型<span class="must"></span></label></div>
							<div class="weui_cell_bd weui_cell_primary">
								<div ng-repeat="(k,v) in pagedata.credit_types" class="fui-cell-label" style="margin-right:0.8rem;float:left;margin-bottom:0.2rem">
									<input type="radio" class="fui fui-radio fui-radio-danger verify-radio" ng-model="pagedata.nowitem.credit_type" value="{{k}}"> {{v}}
								</div>
							</div>
						</div>
						<div class="weui_cell weui_vcode">
							<div class="weui_cell_hd"><label class="weui_label">{{pagedata.showtype==2?'红包':'虚拟币'}}数量<span class="must"></span></label></div>
							<div class="weui_cell_bd weui_cell_primary">
								<input class="weui_input" type="text" ng-model="pagedata.nowitem.num" value="{{pagedata.nowitem.num}}" placeholder="请输入数量">
							</div>
						</div>
				</div>
			</div>
			<div class="fui-navbar">
				<a ng-click="pagedata.checkshowtype()" class="nav-item btn btn-success confirmbtn">确定加入</a>
			</div>
		</div>
	</div>
</div>
<div ng-if="pagedata.showselectgoods" class="popup">
	<div class="popup-body">
		<div class="popup-bottom">
		<i class="closed icon icon-cuowu" ng-click="pagedata.showselectgoods=false"></i>
		<div class="fui-content" style="padding-bottom:2.5rem">
			<div class="fui-fullHigh-group">
				<div class="fui-fullHigh-item menu" id="tab">
					<nav ng-class="{'on':pagedata.ctype =='all'}" ng-click="pagedata.getlist('all',0)">全部商品</nav>
					<nav ng-class="{'on':pagedata.ctype =='isnew'}" ng-click="pagedata.getlist('isnew',0)">新上宝贝</nav>
					<nav ng-class="{'on':pagedata.ctype =='isrecommand'}" ng-click="pagedata.getlist('isrecommand',0)">推荐宝贝</nav>
					<div ng-repeat="c1 in pagedata.category">
						<nav ng-class="{'on':pagedata.ctype ==c1.id}" ng-click="pagedata.getlist('',c1.id)" ng-show="!c1.enabled && pagedata.shopset.category.level !='-1'">{{c1.title}}</nav>
						<div ng-repeat="c2 in pagedata.category.childs[c1.id]">
							<nav ng-class="{'on':pagedata.ctype ==c2.id}" ng-click="pagedata.getlist('',c2.id)" ng-show="!c2.enabled && pagedata.shopset.category.level>=2">{{c2.title}}</nav>
							<nav ng-repeat="c3 in pagedata.category.childs[c2.id]" ng-class="{'on':pagedata.ctype ==c3.id}" ng-click="pagedata.getlist('',c3.id)" ng-show="!c3.enabled && pagedata.shopset.category.level>=3">{{c3.title}}</nav>
						</div>
					</div>
				</div>
				<div class="fui-fullHigh-item container modal-swiper-y">
						<p ng-if="pagedata.list.length<1" class="text-center text-cancel empty" style="margin-top:2rem;color:#999">暂时没有任何商品</p>
						<div class="fui-list-group goods-list-group" style="padding:0;margin:0;margin-top:1.5rem;background:none">
							<div ng-repeat="g in pagedata.goods" class="fui-list goods-item">
									<div class="fui-list-media">
										<img ng-src="{{tomedia(g.image) || '../core/resource/images/nopic.jpg'}}" class='round'/>
									</div>
									<div class='fui-list-inner'>
										<div class='subtitle'>{{g.title}}</div>
										<div class='text'>
										<span class='text-danger'>￥{{g.price}}</span>
										<div class="fui-number small" style="right:0">
											<div ng-if="pagedata.diygoods[g.id].total>0" class="minus" ng-click="pagedata.minus(g.id)"><i class="icon icon-subtract" style="font-size:0.7rem"></i></div>
											{{pagedata.diygoods[g.id].total}}
											<div class="plus" ng-click="pagedata.plus(g.id,g)"><i class="icon icon-tianjia" style="font-size:0.7rem"></i></div>
										</div>
										</div>
									</div>
							</div>
						</div>
						<div ng-if="loading" class='infinite-loading'><span class='fui-preloader'></span><span class='text'> 正在加载...</span></div>
			   
				</div> 
			</div>
			<div class="fui-navbar">
				<a aria-hidden="true" data-dismiss="modal" ng-click="pagedata.checkgoods()" class="nav-item btn btn-success confirmbtn">确定加入</a>
			</div>
		</div>
</div>
</div>
</div>
<div ng-include="sys_html('_footer')"></div>
<script>
scope.pagedata.pay_submit=function(post,post_url,complete_url){
	scope.post_json(post_url,post,function(result){
		if(result.order_id){
			scope.pagedata.order_id=result.order_id;
			scope.$evalAsync();
			scope.tool.pay(result.pay_id,function(res){
					if(res.type=='success'){
						scope.message('支付成功！','success',complete_url);
					}else{
						scope.message('支付失败！','success',complete_url);
					}
			},'','',complete_url,complete_url);
		}
	});
}
//刷新总数和总价
scope.pagedata.refresh=function(){
	var total=0,oneprice=0.00;
	var jiangs=scope.pagedata.post.jiangs;
	for(var i=0;i<jiangs.length;i++){
		if(jiangs[i].type==0){
			oneprice +=jiangs[i].price*jiangs[i].total;
		}else if(jiangs[i].type==2){
			oneprice +=jiangs[i].num*1;
		}else if(jiangs[i].type==3){
			oneprice +=jiangs[i].num/scope.pagedata.credit_rates[jiangs[i].credit_type];
		}
	}
	scope.pagedata.post.oneprice=oneprice;
	scope.pagedata.post.totalprice=oneprice*scope.pagedata.post.total;
	scope.$evalAsync();
}
scope.loading = true;  //状态标记
scope.isnodata = false;
scope.pagedata.goods =[];
scope.pagedata.diygoods=[];
scope.pagedata.ctype ='all'
scope.pagedata.post.total=1;
//滚动加载
scope.pagedata.params = {};
scope.pagedata.params.keyword = ''
var page = 1;
scope.pagedata.getlist=function(order,cid){
		order=order?order:''
		if(order){
			page = 1;
			scope.pagedata.goods =[];
			scope.pagedata.ctype =order
		}else if(cid){
			page = 1;
			scope.pagedata.goods =[];
			scope.pagedata.ctype =cid
		}
		scope.get('jy_weishop/get_data/getgoods/page='+page+'&keyword='+scope.pagedata.params.keyword+'&order='+order+'&cid='+cid,function(data){
					if(data.error !=1){
						for (var i=0;i<data.length;i++){
									scope.pagedata.goods.push(data[i]);
						}
						if(page >1){
									$("#goodslist").animate({scrollTop:0},300);
						}
						if(data.length<1){
									scope.isnodata=true;
						}
						page++;
						scope.loading = false;
						scope.$evalAsync();
						//getmpmansory();
					}else{
						console.log('error!');
					};
		});
}
scope.pagedata.getlist('all',0);
scope.pagedata.scroll_bottom=function(){
	if(!scope.isnodata && !scope.loading){
			scope.pagedata.getlist();
	}
}
//减少
scope.pagedata.minus=function(goodsid){
	var g = scope.pagedata.diygoods[goodsid]
	if(g.total<=0){
		return false;
	}
	g.total--;
	if(g.total<=0){
		
	}
	scope.pagedata.diygoods[goodsid]=g;
	scope.$evalAsync();
}
//增加
scope.pagedata.plus=function(goodsid,nowgoods){
	var g = scope.pagedata.diygoods[goodsid]
	if(!g){
		g={
			'title':nowgoods.title,
			'subtitle':nowgoods.subtitle,
			'image':nowgoods.image,
			'id':nowgoods.id,
			'price':nowgoods.price,
			'total':1,
			'goodstotal':nowgoods.total,
		};
	}else{
		g.total++;
	}
	console.log(nowgoods);
	if(g.total>=nowgoods.total){
		scope.message('不能再添加了，已超过库存！','error');
		return false;
	}
	
	scope.pagedata.diygoods[goodsid]=g;
	scope.$evalAsync();
}
//减少
scope.pagedata.minus2=function(index){
	var g = scope.pagedata.post.jiangs[index]
	if(g.total<=0){
		return false;
	}
	g.total--;
	if(g.total<=0){
		scope.pagedata.post.jiangs.splice(index,1)
	}
	scope.pagedata.refresh();
}
//增加
scope.pagedata.plus2=function(index){
	var g = scope.pagedata.post.jiangs[index]
	g.total++;
	if(g.total>=g.goodstotal){
		scope.message('不能再添加了，已超过库存！','error');
		return false;
	}
	scope.pagedata.post.jiangs[index]=g;
	scope.pagedata.refresh();
}
//减少
scope.pagedata.minus3=function(){
	if(scope.pagedata.post.total<=1){
		scope.message('不能再减少了！只是购买一个礼包！','error');
		return false;
	}
	scope.pagedata.post.total --;
	scope.pagedata.refresh();
}
//增加
scope.pagedata.plus3=function(){
	scope.pagedata.post.total ++;
	scope.pagedata.refresh();
}
scope.pagedata.checkgoods=function(){
	var diygoods=scope.pagedata.diygoods;
	var isnogoods=true;
	diygoods.forEach(function(goodsinfo){
		if(goodsinfo.id){
			isnogoods=false;
			scope.pagedata.post.jiangs.push({
				'type':0,
				'typename':'商品',
				'title':goodsinfo.title,
				'desc':goodsinfo.subtitle,
				'image':goodsinfo.image,
				'goodsid':goodsinfo.id,
				'price':goodsinfo.price,
				'total':goodsinfo.total,
				'goodstotal':goodsinfo.goodstotal,
				'goods':{
					'title':goodsinfo.title,
					'subtitle':goodsinfo.subtitle,
					'image':goodsinfo.image,
					'price':goodsinfo.price,
				}
			});
		}
	});
	if(isnogoods){
		scope.message('请先添加商品！！','error');
	}else{
		scope.pagedata.showselectgoods=false;
		scope.pagedata.diygoods=[];
	}
	scope.pagedata.refresh();
}
scope.pagedata.checkshowtype=function(){
	if(!scope.pagedata.nowitem.title){
		scope.message('请填写礼品名称！！','error');
		return false;
	}
	if(!scope.pagedata.nowitem.num || scope.pagedata.nowitem.num<=0){
		scope.message('请填写礼品数量！！','error');
		return false;
	}
	var credit_title='';
	if(scope.pagedata.nowitem.type==3){
		if(!scope.pagedata.nowitem.credit_type){
			scope.message('请选择虚拟币类型！！','error');
			return false;
		}
		credit_title=scope.pagedata.credit_types[scope.pagedata.nowitem.credit_type];
	}
	scope.pagedata.post.jiangs.push({
		'type':scope.pagedata.nowitem.type,
		'title':scope.pagedata.nowitem.title,
		'desc':scope.pagedata.nowitem.desc,
		'num':scope.pagedata.nowitem.num,
		'credit_type':scope.pagedata.nowitem.credit_type?scope.pagedata.nowitem.credit_type:'',
		'credit_title':credit_title
	});
	scope.pagedata.showtype=false
	scope.pagedata.refresh();
}
</script>